﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL.Users;
using BLL.Users.Impl;
using Utils;

//Author By lijunlin

public partial class Page_Register_RegisterOfExpert : System.Web.UI.Page
{
    //用户管理业务操作对象
    private UserManageBO userManageBO;
    //用户编号
    private string userId;

    protected void Page_Load(object sender, EventArgs e)
    {
        userManageBO = new UserManageBOImpl();
        userId = WebUtil.GetIdentifier(Session["userId"]);

        //显示专家个人信息
        if (!IsPostBack)
        {
            Expert expert = (Expert)userManageBO.ShowDetail(userId);
            txtEditProfileExpertFirstName.Text = expert.ExpertFirstName;
            txtEditProfileExpertLastName.Text = expert.ExpertLastName;
            txtEditProfileExpertPhone.Text = expert.ExpertPhone;
            txtEditProfileExpertAddress.Text = expert.ExpertAddress;
            txtEditProfileExpertCity.Text = expert.ExpertCity;
            txtEditProfileExpertPostalCode.Text = expert.ExpertPostalCode;
            txtEditProfileExpertIntroduce.Text = expert.ExpertIntroduce;

            listEditProfileExpertState_Province.SelectedValue = expert.ExpertState;
            listEditProfileExpertExpertType.SelectedValue = expert.ExpertType;
        }
    }

    //编辑专家个人信息
    protected void btnEditProfileExpert_Click(object sender, ImageClickEventArgs e)
    {
        //输入校验
        //数据收集
        //实体封装
        Expert expert = new Expert
        {
            ExpertId=userId,
            ExpertFirstName=txtEditProfileExpertFirstName.Text,
            ExpertLastName=txtEditProfileExpertLastName.Text,
            ExpertPhone = txtEditProfileExpertPhone.Text,
            ExpertType = listEditProfileExpertExpertType.SelectedValue,
            ExpertState = listEditProfileExpertExpertType.SelectedValue,
            ExpertIntroduce = txtEditProfileExpertIntroduce.Text,
            ExpertPostalCode = txtEditProfileExpertPostalCode.Text,
            ExpertCity = txtEditProfileExpertCity.Text,
            ExpertAddress=txtEditProfileExpertAddress.Text          
        };
        //接口调用
        bool result = userManageBO.EidtProfile(userId, expert);
        //显示结果
        if (result)
        {
            Response.Write(WebUtil.GetTipsAndRedirect("Edit Profile Success!", Request.Url, "Home.aspx"));
        }
        else 
        {
            Response.Write(WebUtil.GetTipsAndRedirect("Edit Profile Failure!", "EditProfileExpert.aspx"));
        }
    }


}